package com.imfondof.mvc_mvp_mvvm.mvvm;

import android.app.Application;
import android.view.View;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

import com.imfondof.mvc_mvp_mvvm.bean.Account;
import com.imfondof.mvc_mvp_mvvm.callback.MCallback;

public class MVVMViewModel extends BaseObservable {
    private MVVMModel model;
    private String input;
    private String result;

    public MVVMViewModel(Application application) {
        model = new MVVMModel();
    }

    public void getData(View view) {
        model.getAccountData(input, new MCallback() {
            @Override
            public void onSuccess(Account account) {
                setResult(account.getName() + "|" + account.getLevel());
            }

            @Override
            public void onFailed() {
                setResult("无数据");
            }
        });
    }

    @Bindable
    public String getInput() {
        return input;
    }

    public void setInput(String input) {
        this.input = input;
        notifyPropertyChanged(com.imfondof.mvc_mvp_mvvm.BR.input);
    }

    @Bindable
    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
        notifyPropertyChanged(com.imfondof.mvc_mvp_mvvm.BR.result);
    }
}
